<script type="text/javascript">
    function ajaxQuickUpdate(id){
        var status = 0;                
        if($("#status_" + id).is(":checked")){ status = 1; }        
                
        var strUrl = "<?php echo Url::createUrl("smsKuteNew/ajaxQuickUpdate");?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {                
                status:status
                , id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    }
    function ajaxDelete(id){
        var strUrl = "<?php echo Url::createUrl("smsKuteNew/ajaxDelete") ?>";
        if(confirm("Bạn có muốn tiếp tục không?")){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Xóa thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>
<div class="main clearfix">
    <div class="Tabs clearfix">
        <ul class="clearfix">
            <li><a href="<?php echo Url::createUrl("appSmsKuteNew/index");?>"><span>App Sms Kute</span></a></li>
            <li><a href="<?php echo Url::createUrl("smsKuteNew/index");?>" class="active"><span>Sms Kute</span></a></li>                        
        </ul>                
    </div>
    <div class="box clearfix bottom30">
        <div class="title-blue"><h3><strong>SMS KUTE </strong></h3></div>
        <form action="" method="GET">
            <ul class="form4">
                <li class="clearfix">
                    <label><strong>Từ ngày </strong>:</label>
                    <div class="filltext">
                        <?php
                            $this->widget(
                                "zii.widgets.jui.CJuiDatePicker"
                                , array(
                                    "name"=>"toDate"
                                    , "id"=>"toDate"
                                    , "value"=>$search["toDate"]                                                                
                                    , "options"=> array(
                                        'showAnim' => 'fold'
                                        , 'dateFormat' => 'dd-mm-yy'
                                        , 'changeYear' => 'true'
                                        , 'changeMonth' => 'true'
                                        , 'showOn' => 'both'
                                        , 'buttonText' => '<input type="button" name="" value="" class="ic-date">'
                                    )
                                    , 'htmlOptions' => array(
                                        'style' => 'width:170px'
                                        , 'class' => 'form'
                                    )
                                )
                            );
                        ?>                                       
                        &nbsp;<strong>đến ngày</strong> &nbsp; 
                        <?php
                            $this->widget(
                                "zii.widgets.jui.CJuiDatePicker"
                                , array(
                                    "name"=>"fromDate"
                                    , "id"=>"fromDate"
                                    , "value"=>$search["fromDate"]                                                                
                                    , "options"=> array(
                                        'showAnim' => 'fold'
                                        , 'dateFormat' => 'dd-mm-yy'
                                        , 'changeYear' => 'true'
                                        , 'changeMonth' => 'true'
                                        , 'showOn' => 'both'
                                        , 'buttonText' => '<input type="button" name="" value="" class="ic-date">'
                                    )
                                    , 'htmlOptions' => array(
                                        'style' => 'width:170px'
                                        , 'class' => 'form'
                                    )
                                )
                            );
                        ?>
                    </div>
                </li>


                <li class="clearfix">
                    <label><strong>Tiêu đề</strong>:</label>
                    <div class="filltext">
                        <input style="width:203px;margin-right:31px;" name="title" value="<?php echo $search["title"];?>" type="text" />                    
                        <strong>Giá </strong>
                        <select style="width:203px;margin-right:14px" name="price">
                            <option value="">Tất cả</option>
                            <option value="15000" <?php if($search["price"]=="15000") echo "selected";?> >15.000</option>
                            <option value="10000" <?php if($search["price"]=="10000") echo "selected";?> >10.000</option>
                            <option value="5000" <?php if($search["price"]=="5000") echo "selected";?> >5.000</option>
                        </select>
                    </div>
                </li>
               
                <li class="clearfix">
                    <label><strong>Tình trạng</strong>:</label>
                    <div class="filltext">                    
                        <select style="width:203px;margin-right:14px" name="status">
                            <option value="">Tất cả</option>
                            <option value="1" <?php if($search["status"]=="1") echo "selected";?> >Hiển thị</option>
                            <option value="0" <?php if($search["status"]=="0") echo "selected";?> >Ẩn</option>                            
                        </select>
                        <strong>App </strong>
                        <select style="width:203px;margin-right:14px" name="eventId">
                            <option value="">Tất cả</option>
                            <?php foreach($apps as $row) { ?>
                            <option value="<?php echo $row["id"];?>" <?php if($search["eventId"]==$row["id"]) echo "selected";?> ><?php echo $row["title"];?></option>
                            <?php } ?>                            
                        </select>
                    </div>

                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input type="submit" value=" Tìm kiếm" class="btn-bigblue"> 
                    </div>
                </li>

            </ul>
        </form>
    </div>
    <div class="box">
        <div class="fillter clearfix">
            <div class="fl">
                Tìm thấy <strong class="clred"><?php echo Common::format_price($totalSms);?></strong> kết quả trong <span class="clred"><?php echo Common::format_price($numberPage);?></span> trang - 
                <a href="<?php echo Url::createUrl("smsKuteNew/add");?>"><input type="button" value=" Thêm mới " class="btn-bigblue"></a>
            </div>
            <?php                
                $url = new Url();            
                $current_url = Common::getCurrentUrl();
                $path = strpos($current_url,'?') !==false ? $current_url.'&' : $current_url.'?';
                $path = str_replace("?page=".$currentPage."&","?",$path);
                $path = str_replace("&page=".$currentPage."&","&",$path);
            ?>            
            <div class="fr">                
                <ul class="paging">
                    <?php echo Paging::show_paging_cp($numberPage, $currentPage, $path);?>
                </ul>
            </div>
        </div>
        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">
                        <td width="3%">STT</td>                        
                        <td width="10%"><strong>Tiêu đề</strong></td>
                        <td width="25%"><strong>Nội dung sms</strong></td>
                        <td width="10%"><strong>App</strong></td>
                        <td width="5%"><strong>Giá</strong></td>
                        <td width="7%"><strong>Tình trạng</strong></td>
                        <td width="5%"><strong>Lượt xem</strong></td>
                        <td width="5%"><strong>Lượt tải</strong></td>
                        <td width="5%"><strong>Thời gian</strong></td>
                        <td width="10%"><strong>Hành động</strong></td>
                    </tr>
                    <?php foreach($sms as $i=>$row) { ?>
                    <tr>
                        <td class="middle"><?php echo $i + 1;?></td>
                        <td class="middle"><?php echo $row["title"];?></td>
                        <td class="middle"><?php echo $row["content"];?></td>
                        <td class="middle"><?php echo $row["event_name"];?></td>
                        <td class="middle"><?php echo Common::format_price($row["price"]);?></td>
                        <td>
                            <input type="checkbox" value="1" id="status_<?php echo $row["id"]?>" <?php if($row["status"]==1) echo "checked";?> > Hiển thị
                        </td>
                        <td class="middle"><?php echo Common::format_price($row["hit"]);?></td>
                        <td class="middle"><?php echo Common::format_price($row["download"]);?></td>
                        <td class="middle"><?php echo date("H:i:s", $row["create_date"]) . "<br>" . date("d-m-Y", $row["create_date"]);?></td>
                        <td class="middle">
                            <a href="javascript:" onclick="ajaxQuickUpdate(<?php echo $row["id"];?>)"> Lưu </a> | 
                            <a href="<?php echo Url::createUrl("smsKuteNew/edit", array("id"=>$row["id"]));?>"> Sửa </a> | 
                            <a href="javascript:" onclick="ajaxDelete(<?php echo $row["id"];?>)"> Xóa </a> 
                        </td>
                    </tr>
                    <?php }?>                    
                </tbody>
            </table>
        </div>
        <div class="fillter clearfix">
            <div class="fr">
                <ul class="paging">
                    <?php echo Paging::show_paging_cp($numberPage, $currentPage, $path);?>
                </ul>
            </div>
        </div>

    </div>
</div>